<?php

namespace Activity;

use C\L\AdmController;

class ShareController extends AdmController
{
    protected function init()
    {
        $this->service = $this->s_activity_share;

        $this->keyworkSearchKeys = [
        'uid',
        ];

        $this->pubSearchKeys = [
        'status',
        ];

        $this->hideKeys = [
        'is_delete'
        ];

        $this->timeToDateKeys = [
        'uptime', 'addtime',
        ];

        $this->updateKeys = [
        'status',
        ];

        $this->createKeys = [
        'uid', 'image',
        ];
    }

    protected function afterSearch(&$data)
    {
        $data['config'] = $this->s_activity_share->getStatusConfig();

        foreach ($data['list'] as &$item) {
            $user = $this->s_user->search($item['uid']);
            $item['name']   = $user['name'] ?? '';
            $item['mobile'] = $user['mobile'] ?? '';
        }

        return true;
    }

    public function indexAction()
    {
        return $this->searchAction();
    }

    public function reviewAction()
    {
        $id     = $this->getValue('id', true, 'int');
        $status = $this->getValue('status', true, 'string');

        try {
            $this->s_activity_share->review($id, $status);
            return $this->success();
        } catch (\Exception $error) {
            return $this->error($error->getMessage());
        }
    }
}
